package ai.people.netmon.youtube.probe.controller;

import ai.people.netmon.framework.domain.youtube.probe.entity.YoutubeAccount;
import ai.people.netmon.framework.domain.youtube.probe.request.YoutubeAccountRequest;
import ai.people.netmon.framework.model.response.PageResponse;
import ai.people.netmon.framework.model.response.Result;
import ai.people.netmon.framework.utils.ResultUtil;
import ai.people.netmon.youtube.probe.service.YoutubeAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * youtube账号采集配置
 *
 * @author yuanqinglong
 * @date 2022/2/25 16:36
 */
@RestController
@RequestMapping("/probe/user")
public class YoutubeAccountController {


    /**
     * youtube用户服务impl
     */
    @Autowired
    private YoutubeAccountService youtubeAccountService;


    /**
     * 获取用户
     *
     * @param id id
     * @return {@link Result}<{@link ?}>
     */
    @GetMapping("{id}")
    public Result<YoutubeAccount> getUser(@PathVariable("id") Long id) {
        return ResultUtil.success(youtubeAccountService.getAccount(id));
    }


    /**
     * 保存用户
     *
     * @param youtubeAccount youtube帐户
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping
    public Result<?> saveUser(@Validated @RequestBody YoutubeAccount youtubeAccount) {
        youtubeAccountService.saveYoutubeAccount(youtubeAccount);
        return ResultUtil.success();
    }


    /**
     * 批量保存用户
     *
     * @param youtubeAccount youtube帐户
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping("/batchSave")
    public Result<?> batchSaveUser(@RequestBody List<YoutubeAccount> youtubeAccount) {
        youtubeAccountService.batchSaveYoutubeAccount(youtubeAccount);
        return ResultUtil.success();
    }


    /**
     * 更新用户
     *
     * @param youtubeAccount youtube帐户
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping
    public Result<?> updateUser(@Validated @RequestBody YoutubeAccount youtubeAccount) {
        youtubeAccountService.updateYoutubeAccount(youtubeAccount);
        return ResultUtil.success();
    }

    /**
     * youtube用户列表
     *
     * @param userRequest 用户请求
     * @return {@link Result}<{@link PageResponse}<{@link YoutubeAccount}>>
     */
    @PostMapping("/list")
    public Result<PageResponse<YoutubeAccount>> listYoutubeAccounts(@RequestBody YoutubeAccountRequest userRequest) {
        PageResponse<YoutubeAccount> twitterAccounts = youtubeAccountService.listYoutubeAccount(userRequest);
        return ResultUtil.success(twitterAccounts);
    }

}
